import Vue from "vue"
import VueRouter from "vue-router"

// 0. 全局注册声明使用 VueRouter
Vue.use(VueRouter)

// 1. 路由组件
import errorRoute from "@/views/errorpages/route"
import mainRoute from "@/views/main/route"
import loginRoute from "@/views/logins/route"
import filmRoute from "@/views/film/route"

// 2. 定义路由选项
const routes = [
    {
        path: "/",
        redirect: "/guide"
    },
    {
        path: "/guide",
        name: 'guide',
        component: () => import("@/views/guide/guide.vue")
    },
    {
        path: "/search",
        name: 'search',
        component: () => import("@/views/search/search.vue")
    },
    {
        path: "/city",
        name: 'city',
        component: () => import("@/views/city/city.vue")
    },
    {
        path: "/cinema/:cinemaId/film/:filmId?/:time?",
        name: 'cinema-detail',
        component: () => import("@/views/cinema/cinema.vue")
    },
    ...filmRoute,
    ...loginRoute,
    ...errorRoute,
    ...mainRoute,
    {
        path: "*",
        redirect: "/404"
    }
]

// 3. 创建路由
const router = new VueRouter({
    mode: 'hash',
    routes,
    base: ""
})

router.beforeEach((to, from, next) => {
    next()
})
// 4. 挂载到根实例
export default router;
